/*******************************************************************************
 * Simple C-K Editor
 * 
 * Copyright (C) 2009 Ingi BROWN - Centre de Gestion Scientifique - Ecole des Mines ParisTech
 * Licensed under the GNU General Public License Version 3.
 * 
 * Simple C-K Editor includes source code and libraries from the JUNG Project (Java Universal Network/Graph Framework) 
 * released under the BSD license. Copyright (c) 2003-2004,  Regents of the University of California and the JUNG Project.
 * 
 * See the License.txt file for more details.
 ******************************************************************************/

/*
 * DeleteVertexMenuItem.java
 *
 * Created on March 21, 2007, 2:03 PM; Updated May 29, 2007
 *
 * Copyright March 21, 2007 Grotto Networking
 *
 */

package edu.ensmp.ckEditor.mousePlugin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import edu.ensmp.ckEditor.ckModel.CKModel;
import edu.ensmp.ckEditor.ckModel.CKModel.Concept;
import edu.ensmp.ckEditor.ckModel.CKModel.Knowledge;
import edu.uci.ics.jung.visualization.VisualizationViewer;

/**
 * A class to implement the deletion of a vertex from within a
 * PopupVertexEdgeMenuMousePlugin.
 * 
 * @author Dr. Greg M. Bernstein
 * @param <E>
 * @param <E>
 */
@SuppressWarnings({ "unchecked", "serial" })
public class DeleteVertexMenuItem<V> extends JMenuItem implements
		VertexMenuListener<V> {
	private V vertex;
	private VisualizationViewer visComp;

	/** Creates a new instance of DeleteVertexMenuItem */
	public DeleteVertexMenuItem() {
		super("Delete Vertex");
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				visComp.getPickedVertexState().pick(vertex, false);
				visComp.getGraphLayout().getGraph().removeVertex(vertex);
				visComp.repaint();
				EditingGraphMousePlugin.save = false;
				if (visComp.getName() == "concept"){
					for (int i = 0; i < CKModel.vecConceptSave.size(); i++ ){
						if (CKModel.vecConceptSave.get(i).equals(((Concept) vertex))){
							CKModel.vecConceptSave.remove(i);
						}
					}
				} else {
					for (int i = 0; i < CKModel.vecKnowledgeSave.size(); i++ ){
						if (CKModel.vecKnowledgeSave.get(i).equals(((Knowledge) vertex))){
							CKModel.vecKnowledgeSave.remove(i);
						}
					}
				}
				
			}
		});
	}

	/**
	 * Implements the VertexMenuListener interface.
	 * 
	 * @param v
	 * @param visComp
	 */
	public void setVertexAndView(V v, VisualizationViewer visComp) {
		this.vertex = v;
		this.visComp = visComp;
		this.setText("Delete Vertex " + v.toString());
	}

}
